package com.spring.security.web.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.mangofactory.swagger.annotations.ApiIgnore;
import com.spring.security.web.model.User;

/**
 * 视图控制器,返回jsp视图给前端
 * 
 * @author StarZou
 * @since 2014年5月28日 下午4:00:49
 **/
@Controller
@RequestMapping("/page")
@ApiIgnore
public class PageController {
    static Logger logger = Logger.getLogger(PageController.class.getName());
    /**
     * 登录页
     */
    @RequestMapping("/login")
    public ModelAndView login() {
        logger.info("---->login");
        Map m = new HashMap();
        m.put("name","json is ok");
        return new ModelAndView("login",m);
    }
    
    /**
     * 首页
     * 
     * @param request
     * @return
     */
    @RequestMapping("index")
    public String index(HttpServletRequest request) {
        logger.info("----->index");
        return "index";
    }

    /**
     * dashboard页
     */
    @RequestMapping("/dashboard")
    public String dashboard() {
        return "dashboard";
    }

    /**
     * 404页
     */
    @RequestMapping("/404")
    public String error404() {
        return "404";
    }

    /**
     * 401页
     */
    @RequestMapping("/401")
    public String error401() {
        return "401";
    }

    /**
     * 500页
     */
    @RequestMapping("/500")
    public String error500() {
        return "500";
    }

    /**
     *
     * @第一个页面
     */
    @RequestMapping("/myfirstpage")
    public ModelAndView myfirstpage() {
        Map s= new HashMap();
        List l = new ArrayList();
        User u = new User();
        u.setId("111111");
        u.setUsername("11111~~~~");
        l.add(u);
        u.setId("22222");
        u.setUsername("22222~~~~");
        l.add(u);
        s.put("list",l);
        s.put("test","hello wojunyu");
        return new ModelAndView("first",s);
    }

    @RequestMapping("/appService")
    public String appService() {
        return "appservice/service";
    }

    @RequestMapping("/upload")
    @ResponseBody
    public Object upload(@RequestParam(value = "file", required = false)MultipartFile file) {
        try {
//            DownFileInfoBean bean = new DownFileInfoBean(null, "C:\\temp",
//                    "TortoiseGit_1.8.14.msi", 5,false,file);
//            DownFileFetch fileFetch = new DownFileFetch(bean);
//            fileFetch.start();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "ok";
    }

    @RequestMapping("/fileUp")
    public String fileUp() {
        return "demo/index";
    }

}